package com.hmy.material.controller;

import com.hmy.material.domain.HmyMateriaFeedStore;
import com.hmy.material.service.StoreService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zxh
 * @version 1.0
 * @description: TODO
 * @date 2024/1/31 12:27
 */
@RestController
@RequestMapping("store")
public class StoreController extends BaseController {
    @Resource
    private StoreService storeService;

    /**
     * 查询存储信息列表
     * @param position 参数一：存储地点
     * @param type 参数二：饲料类型
     * @param dateStart 参数三：存储开始时间
     * @param dateEnd 参数四：存储结束时间
     * @return 返回查询列表
     */
    @RequiresPermissions("material:store:list")
    @GetMapping("list")
    public TableDataInfo selectStoreList(Integer position, Integer type,
                                            String dateStart, String dateEnd){
        startPage();
        List<HmyMateriaFeedStore> purchaseList = storeService.selectStoreList(position, type, dateStart, dateEnd);
        return getDataTable(purchaseList);
    }

    /**
     * 根据ID获取单个存储信息
     * @param id
     * @return
     */
    @RequiresPermissions("material:store:query")
    @GetMapping("getInfo/{id}")
    public AjaxResult selectPurchaseById(@PathVariable Long id){
        return AjaxResult.success(storeService.selectStoreById(id));
    }

    @RequiresPermissions("material:store:add")
    @PostMapping("add")
    public AjaxResult addStore(@RequestBody HmyMateriaFeedStore store) {
        return toAjax(storeService.addStore(store));
    }

    @RequiresPermissions("material:store:update")
    @PostMapping("update")
    public AjaxResult updateStore(@RequestBody HmyMateriaFeedStore store){
        return toAjax(storeService.updateStore(store));
    }

    /**
     * 根据ID删除进货信息
     * @param delIds
     * @return
     */
    @DeleteMapping("del/{delIds}")
    @RequiresPermissions("material:store:del")
    public AjaxResult delStoreById(@PathVariable  Long[] delIds){
        return toAjax(storeService.delStoreByIds(delIds));
    }


    @RequestMapping("findStoreByTypePosition")
    public AjaxResult findStoreByTypePosition(String materiaFeedType, String materiaFeedStorePosition){
        return AjaxResult.success(storeService.findStoreByTypePosition(materiaFeedType, materiaFeedStorePosition));
    }


    /**
     * 根据饲料类型获取该类型的饲料储存量
     * @param materiaFeedType
     * @return
     */
    @RequiresPermissions("material:store:query")
    @GetMapping("selectMateriaFeedStoreNum")
    public AjaxResult selectMateriaFeedStoreNum(String materiaFeedType){
        return AjaxResult.success(storeService.selectMateriaFeedStoreNum(materiaFeedType));
    }



}
